from PIL import ImageGrab


class BarStatus:
    def __init__(self, gameWindow, config: dict):
        self.region_x = gameWindow.x + config['region_x']
        self.region_y = gameWindow.y + config['region_y']

    def is_burst(self):
        try:
            # 截取单个像素点
            color = ImageGrab.grab(bbox=(self.region_x, self.region_y, self.region_x + 1, self.region_y + 1)).getpixel((0, 0))
            # 获取该像素的颜色
            if not all(c < 10 for c in color):
                return True
            else:
                return False
        except Exception as e:
            print(f"获取像素颜色失败: {e}")
            return False